package love.yuanmengrobot.qianyugarden.controller;

import love.yuanmengrobot.qianyugarden.entity.BookEvent;
import love.yuanmengrobot.qianyugarden.entity.ThousandLanguage;
import love.yuanmengrobot.qianyugarden.entity.User;
import love.yuanmengrobot.qianyugarden.service.BookEventService;
import love.yuanmengrobot.qianyugarden.service.CarouselContentService;
import love.yuanmengrobot.qianyugarden.service.ThousandLanguageService;
import love.yuanmengrobot.qianyugarden.service.YuanwenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 千语(ThousandLanguage)表控制层
 *
 * @author CHJY创幻
 * @since 2021-07-13 14:00:41
 */
@Controller
//@RequestMapping("thousandLanguage")
public class ThousandLanguageController {
    /**
     * 服务对象
     */
    @Autowired
    ThousandLanguageService thousandLanguageService;
    @Autowired
    CarouselContentService carouselContentService;
    @Autowired
    YuanwenService yuanwenService;
    @Autowired
    BookEventService bookEventService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping("selectOne")
    public ThousandLanguage selectOne(String id) {
        return this.thousandLanguageService.queryById(id);
    }

    /**
     * 跳转到首页的主要内容区
     *
     * @return
     */
    @RequestMapping("toMainContent")//转发的写法，即跳转到html
    public String toMainContent(HttpServletRequest request, ModelMap map) {
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

        map.put("css_mainContent", basePath + "css/mainContent/mainContent.css");
        map.put("css_carousel", basePath + "css/mainContent/carousel.css");
        map.put("js_mainContent", basePath + "js/mainContent/mainContent.js");
        map.put("js_carousel", basePath + "js/mainContent/carousel.js");

        map.put("tl_label", thousandLanguageService.queryAllByLimitAndLevel(1, 7));
        map.put("img_five", carouselContentService.queryAllByFive());
        map.put("YM_New", yuanwenService.queryAllByLimitAndYM(0, 7));
        map.put("YM_NewRight", yuanwenService.queryAllByLimitAndYM(7, 7));
        map.put("TB_New", yuanwenService.queryAllByLimitAndTB(0, 7));

        map.put("total_New", bookEventService.queryAllByLimitTotal(0, 15));
        map.put("week_New", bookEventService.queryAllByLimitWeek(0, 15));
        map.put("day_New", bookEventService.queryAllByLimitDay(0, 15));





//        bookEventService
//                bookEventService
//                bookEventService

        return "main/mainContent";
    }
}
